package springboot.bigdata.demo.dao.impl;

import cn.hutool.core.collection.CollUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import springboot.bigdata.demo.dao.UserServiceLevelChangeRecordDao;
import springboot.bigdata.demo.mappers.db0.DB0UserServiceLevelChangeRecordMapper;
import springboot.bigdata.demo.mappers.db1.DB1UserServiceLevelChangeRecordMapper;
import springboot.bigdata.demo.model.UserServiceLevelChangeRecord;

import java.util.List;

@Component
public class UserServiceLevelChangeRecordDaoImpl implements UserServiceLevelChangeRecordDao {

    @Autowired
    private DB0UserServiceLevelChangeRecordMapper db0UserServiceLevelChangeRecordMapper;
    @Autowired
    private DB1UserServiceLevelChangeRecordMapper db1UserServiceLevelChangeRecordMapper;

    @Override
    public UserServiceLevelChangeRecord add(UserServiceLevelChangeRecord userServiceLevelChangeRecord) {

        db0UserServiceLevelChangeRecordMapper.insertSelective(userServiceLevelChangeRecord);
        db1UserServiceLevelChangeRecordMapper.insertSelective(userServiceLevelChangeRecord);

        return userServiceLevelChangeRecord;
    }

    @Override
    public int addList(List<UserServiceLevelChangeRecord> userServiceLevelChangeRecordList, int dbType) {

        if (CollUtil.isEmpty(userServiceLevelChangeRecordList)){
            return 0;
        }

        db0UserServiceLevelChangeRecordMapper.insertSelectiveList(userServiceLevelChangeRecordList);
        db1UserServiceLevelChangeRecordMapper.insertSelectiveList(userServiceLevelChangeRecordList);

        return 0;
    }
}
